var Connect = YAHOO.util.Connect,
Panel = YAHOO.widget.Panel,
KeyListener = YAHOO.util.KeyListener,
Event = YAHOO.util.Event,
Dom = YAHOO.util.Dom,
Json = YAHOO.lang.JSON;

var AdminController = {
    
    adminRequestFalse:function(){
        alert('AsyncRequest False');
    },
    setlectedTopMenu:function(elementId){
        var listEl = Dom.get('menu_top').getElementsByTagName('a');
        for(var i= 0; i < listEl.length; i++){
            if(listEl[i].className == 'cpointer selected'){
                listEl[i].className = listEl[i].className.replace('selected', 'noselect');
            }
        }
        if(Dom.get(elementId)){
            Dom.get(elementId).className = Dom.get(elementId).className.replace('noselect', 'selected');
        }
    },
    selectedHeaderControll:function(elementId){
        var listEl = Dom.get('manage-new-pland').getElementsByTagName('a');
        for(var i= 0; i < listEl.length; i++){
            if(listEl[i].className == 'selected'){
                listEl[i].className = '';
            }
        }
        if(Dom.get(elementId)){
            Dom.get(elementId).className = 'selected';
        }
    },
    hiddenLeftDiv:function(){
        var listDiv = Dom.get('left').getElementsByTagName('div');
        for(var i = 0; i < listDiv.length; i++){
            if(listDiv[i].className == 'show'){
                listDiv[i].className = 'hide';
            }
        }
    },

    backToTop:function(){
        window.scrollTo(0,0);
    },

    hiddenCenterDiv:function(){
        var listDiv = Dom.get('maincontentcenter').getElementsByTagName('div');
        for(var i = 0; i < listDiv.length; i++){
            if(listDiv[i].className == 'show'){
                listDiv[i].className = 'hide';
            }
        }
    },

    setElemnetLeftSelected:function(current){
        var listEl = Dom.get('left').getElementsByTagName('a');
        for(var i= 0; i < listEl.length; i++){
            if(listEl[i].className == 'selected'){
                listEl[i].className = listEl[i].className.replace('selected', '');
            }
        }
        if(Dom.get(current)){
            Dom.get(current).className = 'selected';
        }
    },

    showOverlaySuccess:function(messageSuccess){
        AdminController.backToTop();
        Dom.get('confirm-header').innerHTML = 'Thành công';
        Dom.get('confirm-message').innerHTML = messageSuccess;
        AdminController.showOverlayConfirm();
    },

    showOverlayError:function(messageError){
        AdminController.backToTop();
        Dom.get('confirm-header').innerHTML = 'Có lỗi xảy ra';
        Dom.get('confirm-message').innerHTML = messageError;
        AdminController.showOverlayConfirm();
    },

    showOverlayConfirm:function(){
        var x = 450;
        var y = 100;
        AdminController.overlayConfirm = new YAHOO.widget.Panel('overlayConfirm',
        {
            xy:[x,y],
            //            fixedcenter:true,
            close:false,
            visible:false,
            draggable:false,
            modal:true,
            width:"400px",
            zIndex: 255
        });

        // Render the Dialogs
        AdminController.overlayConfirm.render(document.body);
        //        AdminController.overlayConfirm.center();
        document.getElementById('overlayConfirm').style.display = 'block';
        AdminController.overlayConfirm.show();
    },

    closeOverlayConfirm:function(){
        AdminController.overlayConfirm.hide();
    },

    showOverlayConfirmYesNo:function(message, actClickYes, actClickNo){
        AdminController.backToTop();
        Dom.get('confirm-header-yes-no').innerHTML = 'Xác nhận';
        Dom.get('confirm-message-yes-no').innerHTML = message;
        AdminController.overlayConfirmYesNo();
        document.getElementById('confirm-yes').setAttribute('onclick', 'AdminController.closeOverlayConfirmYesNo();'+actClickYes);
        document.getElementById('confirm-no').setAttribute('onclick', 'AdminController.closeOverlayConfirmYesNo();'+actClickNo);
    },

    overlayConfirmYesNo:function(){
        var x = 450;
        var y = 100;
        AdminController.confirmYesNo = new YAHOO.widget.Panel('overlayConfirmYesNo',
        {
            xy:[x,y],
            //            fixedcenter:true,
            close:false,
            visible:false,
            draggable:false,
            modal:true,
            width:"400px",
            zIndex: 255
        });

        // Render the Dialogs
        AdminController.confirmYesNo.render(document.body);
        //        AdminController.overlayConfirmYesNo.center();
        document.getElementById('overlayConfirmYesNo').style.display = 'block';
        AdminController.confirmYesNo.show();
    },

    closeOverlayConfirmYesNo:function(){
        AdminController.confirmYesNo.hide();
    },

    getCustomerRegister:function(){
        AdminController.hiddenCenterDiv();
        var strUrl = '/admin/getCustomerRegister/?ajax=1';
        YAHOO.util.Connect.asyncRequest ('POST', strUrl, {
            success: AdminController.getCustomerRegisterSuccess,
            failure: AdminController.asyncRequestFalse
        });
    },
    
    getCustomerRegisterSuccess:function(xmlhttp){
        var strJsonData = xmlhttp.responseText;
        var aryData = Json.parse(strJsonData);
        if(aryData.intOk == 1){
            Dom.get('list_customer_register').className = 'show';
            Dom.get('list_customer_register').innerHTML = aryData.content;
        }
    },

    viewDetailCustomerRegister:function(){
        var strUrl = '/admin/viewDetailCustomerRegister/?ajax=1';
        YAHOO.util.Connect.asyncRequest ('POST', strUrl, {
            success: AdminController.getDetailCustomerSuccess,
            failure: AdminController.asyncRequestFalse
        });
    },
    
    getDetailCustomerSuccess:function(xmlhttp){
        var strJsonData = xmlhttp.responseText;
        var aryData = Json.parse(strJsonData);
        
    },
    
    createRoom:function(){
        AdminController.hiddenCenterDiv();
        Dom.get('manage_create_room').className = 'show';
    }
    
}

